-- 选择上一次友方选中的
local FightBehavior = require("gameLogic.fight.fightBehavior.FightBehavior")
local SelectLastBehavior = class("SelectLastBehavior", FightBehavior)

function SelectLastBehavior:ctor()
    SelectLastBehavior.super.ctor(self)
end

function SelectLastBehavior:excute(battleReport)
    local skill = self._entity:getNormalSKill()
    local target = skill:getTarget()
    local entitys = self:getSkillTargetEntity(target, skill)
    if #entitys > 0 then
        battleReport:addAttackSkillId(skill:getId())
        skill:actOn(entitys, battleReport)
    end
    self._entity:dispatchActionEnd()
end

function SelectLastBehavior:getSkillTargetEntity(target, skill)
    local FightHelper = require("gameLogic.fight.FightHelper")
    local FightConst = require("const.FightConst")
    local enemys = self:getTargetEntitys(skill:getConfig().attack_idx)
    local param = {}
    param.enemys = enemys
    param.amount = skill:getAmount()
    local targetFunc = FightHelper["_SKILL_TARGET_" .. target]
    return targetFunc(param)
end

function SelectLastBehavior:getTargetEntitys()
    local camp = self._entity:getCamp()
    local enemmys = self._entity:getExcuter():getLastBeAttack()
    local result = {}
    for i = 1, #enemmys do
        if camp ~= enemmys[i]:getCamp() and not enemmys[i]:isDie() then
            table.insert(result, enemmys[i])
        end
    end
    return result
end

return SelectLastBehavior
